package cn.lds.j375.healthexam.hanlder;

import cn.lds.j375.healthexam.dto.ResultDTO;
import cn.lds.j375.healthexam.exception.SysException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandl {

    private SysException sysException;

    @ExceptionHandler
    public String exception(Exception e, Model model){
        if (e instanceof  SysException){
            sysException = (SysException) e;
        }else {
            sysException = new SysException(ResultDTO.buildError("系统升级中……"));
            e.printStackTrace();
        }

        model.addAttribute("exceptionMsg",sysException.getExceptionMsg());

        return "error";
    }
}
